<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>老师信息表单</title>
    <!-- 引入element-ui样式 -->
    <link rel="stylesheet" href="../../../plugins/element-ui/index.css">
<!--    上传图片样式-->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
    </style>
</head>
<body>

<div id="app">

    <el-container style="height: 800px; border: 1px solid #eee">
        <el-container>
            <div style="width: 100%;position: relative">

                <div style=";margin-bottom: 80px;">


                    <el-button type="warning" style="float: right" @click="Up_Add_dialogShow(null)">新增薪水</el-button>
                </div>

                <el-table   size="medium" current-row-key="id"  :data="dataList" stripe highlight-current-row>
                    <el-table-column type="index" align="center" label="序号"></el-table-column>
                    <el-table-column prop="jobNumber" label="工号" align="center"></el-table-column>
                    <el-table-column prop="major" label="专业" align="center"></el-table-column>
                    <el-table-column prop="type" label="类型" align="center"></el-table-column>
                    <el-table-column prop="salary" label="薪水" align="center"></el-table-column>
                    <el-table-column prop="bonus" label="奖金" align="center"></el-table-column>
                    <el-table-column prop="time" label="时间" align="center"></el-table-column>
                    <el-table-column prop="remark" label="备注" align="center"></el-table-column>
                    <el-table-column label="操作" align="center">
                        <template slot-scope="scope">
                            <el-button type="primary" style="float: left;width: 50px" size="mini" @click="Up_Add_dialogShow(scope.row)">编辑</el-button>
                            <el-button type="danger" style="float: right;margin-top: -28px" size="mini" @click="DeleteSalary(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <!--分页组件-->
                <el-pagination
                        class="pagination"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>


                <!--2.修改 薪水弹框-->
                <el-dialog :title="title" style="height: 650px"  :visible.sync="dialog_update">
                    <el-form :model="formData_update" :rules="rules" ref="formData_update" label-width="100px" class="demo-formData_update">
                        <el-form-item  label="工号：" prop="jobNumber">
                            <el-input v-model="formData_update.jobNumber"></el-input>
                        </el-form-item>


                        <el-form-item  label="类型" prop="type">
                            <template>
                                <el-select v-model="formData_update.type" placeholder="请选择">
                                    <el-option
                                            v-for="item in options1"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-form-item>

                        <el-form-item  label="专业：" prop="major">
                            <template>
                                <el-select v-model="formData_update.major" placeholder="请选择">
                                    <el-option
                                            v-for="item in options2"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-form-item>

                        <el-form-item  label="薪水：" prop="salary">
                            <el-input v-model="formData_update.salary"></el-input>
                        </el-form-item>



                        <el-form-item  label="奖金：" prop="bonus">
                            <el-input v-model="formData_update.bonus"></el-input>
                        </el-form-item>

                        <el-form-item  label="时间：" prop="time">
                            <template>
                                <div class="block">
                                    <el-date-picker
                                            v-model="formData_update.time"
                                            type="date"
                                            placeholder="选择日期">
                                    </el-date-picker>
                                </div>
                            </template>
                        </el-form-item>


                        <el-form-item  label="备注：" prop="remark">
                            <el-input v-model="formData_update.remark"></el-input>
                        </el-form-item>

                        <el-form-item>
                            <el-button type="primary" @click="UpdateSalary">确定修改</el-button>
                            <el-button @click="center">取消</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>

                <!--3.新增 薪水弹框-->
                <el-dialog :title="title" style="height: 650px"  :visible.sync="dialog_add">
                    <el-form :model="formData_add" :rules="rules" ref="formData_add" label-width="100px" class="demo-formData_add">
                        <el-form-item  label="工号：" prop="jobNumber">
                            <el-input v-model="formData_add.jobNumber"></el-input>
                        </el-form-item>


                        <el-form-item  label="类型" prop="type">
                            <template>
                                <el-select v-model="formData_add.type" placeholder="请选择">
                                    <el-option
                                            v-for="item in options1"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-form-item>

                        <el-form-item  label="专业：" prop="major">
                            <template>
                                <el-select v-model="formData_add.major" placeholder="请选择">
                                    <el-option
                                            v-for="item in options2"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-form-item>

                        <el-form-item  label="薪水：" prop="salary">
                            <el-input v-model="formData_add.salary"></el-input>
                        </el-form-item>



                        <el-form-item  label="奖金：" prop="bonus">
                            <el-input v-model="formData_add.bonus"></el-input>
                        </el-form-item>

                        <el-form-item  label="时间：" prop="time">
                            <template>
                                <div class="block">
                                    <el-date-picker
                                            v-model="formData_add.time"
                                            type="date"
                                            placeholder="选择日期">
                                    </el-date-picker>
                                </div>
                            </template>
                        </el-form-item>


                        <el-form-item  label="备注：" prop="remark">
                            <el-input v-model="formData_add.remark"></el-input>
                        </el-form-item>

                        <el-form-item>
                            <el-button type="primary" @click="AddSalary">确定添加</el-button>
                            <el-button @click="center">取消</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>

            </div>
        </el-container>
    </el-container>

</div>


<script src="../../../plugins/vue/vue.js"></script>

<!-- 引入element-ui组件库 -->
<script src="../../../plugins/element-ui/index.js"></script>

<!-- 引入axios -->
<script src="../../../plugins/axios/axios.min.js"></script>

<script>
    new Vue({
        el:'#app',    //element
        data:{

            adminTwoInfo1:{},
            //显示的数据
            dataList:[],


            //element-ui分页插件
            pagination: {
                //分页相关模型数据 1
                currentPage: 1,//当前页码1
                pageSize:5,//每页显示的记录数1
                total:0,//总记录数1
            },

            //修改弹框内容
            formData_update:{
                image:'',
            },
            dialog_update:false,


            //新增弹框内容
            formData_add:{
                image:'',
            },
            dialog_add:false,

            options1: [{
                value: '教职工',
                label: '教职工'
            },{
                value: '管理员',
                label: '管理员'

            },],
            options2: [{
                value: '计算机',
                label: '计算机'
            },{
                value: '软件工程',
                label: '软件工程'

            },],
        },

        created() {
            const adminTwoInfo = window.localStorage.getItem('adminTwo')
            console.log("adminTwoInfo1:::"+adminTwoInfo)
            if (adminTwoInfo) {
                this.adminTwoInfo = JSON.parse(adminTwoInfo)
            }
            console.log("adminTwoInfo2:::"+adminTwoInfo)

            this. getAll()
        },

        methods:{

            getAll(){
                axios.get("/salarys/getPageSalary/"+this.pagination.currentPage+"/"+this.pagination.pageSize).then((res)=>{
                    console.log("res:")
                    console.log(res)
                    this.dataList=res.data.data.records
                    this.pagination.total=res.data.data.total

                })
            },

            //切换页码
            handleCurrentChange(currentPage) {
                console.log("切换页码:")
                this.pagination.currentPage=currentPage;
                console.log(currentPage)
                this.getAll();
            },

            //修改弹框的显示和隐藏
            Up_Add_dialogShow(row){
                //弹框显示时,先清空弹框
                console.log(row)
                if (row!==null) {
                    //数据回显
                    this.formData_update = row
                    this.imageUrl=row.image
                    //弹框显示
                    this.dialog_update=true
                }else {
                    this.dialog_add=true
                }
            },
            //确定添加
            AddSalary(){
                axios.post("/salarys/addSalary",this.formData_add).then((res)=> {
                    if (res.data.code){
                        this.$message.success(res.data.msg)
                    }else{
                        this.$message.error(res.data.msg)
                    }
                }).finally(()=>{
                    this.getAll();
                    this.dialog_add=false;
                    this.formData_add=''
                })
            },

            //确定修改
            UpdateSalary(){

                axios.put("/salarys/updateSalary",this.formData_update).then((res)=>{     //修改数据回显
                    if (res.data.code){
                        // alert("删除成功")
                        this.$message.success(res.data.msg)
                    }else{
                        this.$message.error(res.data.msg)
                    }
                }).finally(()=>{
                    this.getAll();
                    this.dialog_update=false;
                })
            },


            //通过id删除
            DeleteSalary(row){
                this.$confirm("此操作删除当薪水全部信息，是否继续?","提醒",{type: 'info'
                }).then(()=>{
                    axios.delete("/salarys/deleteSalary/"+row.id).then((res)=> {
                        console.log("deleteById:")
                        console.log(res)
                        if (res.data.code){
                            // alert("删除成功")

                            this.$message.success(res.data.msg)
                        }else{
                            this.$message.error(res.data.msg)
                        }
                    }).finally(()=>{
                        this.getAll()
                    })
                }).catch(()=>{
                    //取消删除
                    this.$message.info("取消删除操作")
                })

            },

            center() {
                this.dialog_update=false
                this.dialog_add=false
                this.$message.info("取消操作")
            },
        }
    })

</script>
</body>
</html>